﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using KaiXin001er.Objects;
using KaiXin001er.UTIL;

namespace KaiXin001er
{
    public partial class ProgrameConfiger : Form
    {
        public ProgrameConfiger()
        {
            InitializeComponent();
            Initialize();
        }

        private void Initialize()
        {
            this.txt_DelayTime.Text = ConfigManager.ProgramConfig.DelayTime.ToString();
            try
            {
                cb_EnableLoop.Checked = ConfigManager.ProgramConfig.EnableCycle;
                num_ParkFr.Value = ConfigManager.ProgramConfig.HappyCycle;
                time_parktime.Value = ConfigManager.ProgramConfig.HappyTime;
                cb_EnableLoop_CheckedChanged(null, null);
                cb_debugEnable.Checked = ConfigManager.ProgramConfig.OpenDebug;
            }
            catch (Exception) { }
        }

        private void btn_save_Click(object sender, EventArgs e)
        {
            ProgramConfiger pc = ConfigManager.ProgramConfig;
            pc.DelayTime = int.Parse(txt_DelayTime.Text);
            pc.HappyCycle = (int) num_ParkFr.Value;
            pc.HappyTime = time_parktime.Value;
            pc.EnableCycle = cb_EnableLoop.Checked;
            pc.OpenDebug = cb_debugEnable.Checked;
            ConfigManager.SaveProgramConfig();
            this.Dispose();
        }

        private void cb_EnableLoop_CheckedChanged(object sender, EventArgs e)
        {
            gb_LoopSettings.Enabled = cb_EnableLoop.Checked;
        }
    }
}
